package com.pussinboots.morning.sync.service.impl;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.lang.reflect.InvocationTargetException;

public class ServiceImpl_<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> {
    /**
     * 利用反射动态调用方法
     * @param methodName
     * @param paramObj
     * @return
     */
    public Boolean invoke(String methodName, Object[] paramObj){
        Boolean result = false;
        Class[] classes = new Class[0];
        if (paramObj !=null && paramObj.length > 0) {
            classes = new Class[paramObj.length];
            for (int i=0; i<paramObj.length; i++) {
                classes[i] = paramObj.getClass();
            }
        }
        try {
            this.getClass().getDeclaredMethod(methodName, classes).invoke(this, paramObj);
            result = true;
        } catch (Exception e) {
        }

        return result;
    }
}
